
$("#login-button").click(function(obj){
	 event=	obj;
	 validateForm();
	 
	
});
 
 
 document.onkeydown = function(e){
     var ev = document.all ? window.event : e;
     if(ev.keyCode==13) {
    	// validateForm();
    	 $("#login-button").click();
    	 
     }
 }
 
 
 function validateForm(){
	 var passwd=$("#password").val();
     var usercode=$("#username").val();
    
      if(passwd!=""&&usercode!=""){
    	   event.preventDefault();
    	  $.ajax({
     	            //几个参数需要注意一下
     	                type: "POST",//方法类型
     	                dataType: "json",//预期服务器返回的数据类型
     	                url: url+"/dologin" ,//url
     	                data: {
     	                	"usercode":usercode,
     	                	"passwd":passwd
         	                },
     	                success: function (result) {
     	                	
                               if(result.msg=="0"){
                                
                            	   location=url+"/main";
               	               	
              	               	 
                                   }else{
                                	  
  
                                	   $.alert({
                    	           	        title: '提示',
                    	           	        content: result.msg,
                    	           			buttons: {
                    	           				confirm: {
                    	           					text: '确认',
                    	           					btnClass: 'btn-primary',
                    	           				}
                    	           			}
                    	           	    });
                               		
                                       }

     	                },
     	                error : function(e) {
     	                	
     	                	$.alert({
     	           	        title: '提示',
     	           	        content: '登陆失败,'+JSON.stringify(e),
     	           			buttons: {
     	           				confirm: {
     	           					text: '确认',
     	           					btnClass: 'btn-primary',
     	           				}
     	           			}
     	           	    });
     	                	
     	                }
     	            });
    	   
           }else{
        	   
        	   $.alert({
        	        title: '提示',
        	        content: '请输入账号或密码',
        			buttons: {
        				confirm: {
        					text: '确认',
        					btnClass: 'btn-primary',
        				}
        			}
        	    });
        	   
           }
          
 	
	} 